<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="divTyping"></div>
    <script>

        var str = 'js实现自动打字效果实现'
        var i = 0;
        function typing() {
            console.log(111);
            var divTyping = document.getElementById('divTyping')
            if (i <= str.length) {
                divTyping.innerHTML = str.slice(0, i++) + '_'
                // 递归调用
                setTimeout('typing()', 30)

            }
            else {
                // 打字结束，清除_
                divTyping.innerHTML = str
            }
        }
        typing()

    </script>
</body>

</html>